"""
A class to exercise the JT core functions.
"""
import itk
import vtk
import JT
from numpy import array

def Test_JTVolumeRendering():
    """
    Test the volume rendering implemented in JT
    """
    #inputVolFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.mhd'
    inputVolFileName = r'C:\Users\bryan\phd\SpineDataImages\CT\9495.mhd'
    #staFile = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.sta'
    staFile = r'C:\Users\bryan\phd\SpineDataImages\CT\9495.sta'
    calFile = 'C:/Users/bryan/bryan-code/2D3D/vert1/fluoro/ushortim080-LAT.cal'

#===============================================================================
#    
#    Generate Lateral Projection
#    
#===============================================================================
    drr = JT.DRR()

#===============================================================================
#    
#    Automatic calibration
#    
#===============================================================================
    cal = JT.ExternalCalibration()
    cal.LoadConsolidatedCalibration(calFile)
    cal.LoadStaFile(staFile)
    
    drr.SetExternalCalibration(cal)

    volume = JT.Volume()
    volume.SetVolumeFilename(inputVolFileName)
    volume.SetOriginalTransform(cal.volumeTransform)
    volume.AddBodyCenter((3.906, 2.17, -7.378))
    
    drr.AddVolume(volume)
    
    drr.Render()
    drr.InteractionOn()
    drr.StartInteraction()
    print "Time to Render: ", drr.GetRenderTime(), ", Frame Rate: ", 1/drr.GetRenderTime()

    #Debugging, save the final generated image
    #drr.SaveGeneratedImage('C:/Users/bryan/bryan-code/trunk/Images/CurrentDRR.mhd')


if __name__ == "__main__":
    Test_JTVolumeRendering()